define(function(require, exports, module) {
    var moment = require("moment");
    var _ = require("underscore");
    var $ = require('jquery');
    var util = require('util');
    require('authorize');
    require("permission");
    require("lib/jquery-date-range-picker/jquery.daterangepicker");
    var Highcharts = require("lib/highcharts/js/highcharts.src");

    var $http = {
        get: function (url, data) {
            var deferred = $.Deferred();
            util.myAjax({
                url: url,
                type: 'GET',
                data: data,
                success: function (data) {
                    if (data.retCode != '0') {
                        deferred.reject();
                        util.alert(data.retMsg);
                    } else {
                        deferred.resolve(data.data);
                    }
                },
                complete: function (xhr, txtStatus) {
                    if (xhr.status == 0) {
                        deferred.reject();
                    }
                    else if (xhr.status != 200) {
                        // 处理 error 时没有回调的解决办法
                        deferred.reject();
                    }
                }
            });

            return deferred.promise();
        },

        post: function (url, data) {
            var deferred = $.Deferred();
            util.myAjax({
                url: url,
                type: 'GET',
                data: data,
                success: function (data) {
                    if (data.retCode != '0') {
                        deferred.reject();
                        util.alert(data.retMsg);
                    } else {
                        deferred.resolve(data.data);
                    }
                },
                complete: function (xhr, txtStatus) {
                    if (xhr.status == 0) {
                        deferred.reject();
                    }
                    else if (xhr.status != 200) {
                        // 处理 error 时没有回调的解决办法
                        deferred.reject();
                    }
                }
            });

            return deferred.promise();
        }
    };

    Date.prototype.format = function (fmt) { //author: meizz 
        var o = {
            "M+": this.getMonth() + 1, //月份 
            "d+": this.getDate(), //日 
            "h+": this.getHours(), //小时 
            "m+": this.getMinutes(), //分 
            "s+": this.getSeconds(), //秒 
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
            "S": this.getMilliseconds() //毫秒 
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    };

    var FansAnalyse = {};
    (function (ns) {

        ns.InitFansAnalyseData = function () {
            $http.get('/api/index.php?r=qmyx/fans-analysis/load-fans-analysis-data')
                .then(function (data) {
                    if (data) {
                        $.each(data, function (i, o) {
                            switch (o.AnalyseType) {
                                case "1":
                                    $('#key_index td:eq(0)').html(ns.wrapAnalyseData('新关注人数', o));
                                    break;
                                case "2":
                                    $('#key_index td:eq(1)').html(ns.wrapAnalyseData('取消关注人数', o));
                                    break;
                                case "3":
                                    $('#key_index td:eq(2)').html(ns.wrapAnalyseData('净增关注人数', o));
                                    break;
                                case "4":
                                    $('#key_index td:eq(3)').html(ns.wrapAnalyseData('累积关注人数', o));
                                    break;
                            }
                        });
                    }
                });

            $http.get('/api/index.php?r=qmyx/fans-analysis/get-recognition-categories')
                .then(function(data) {
                    if (data) {
                        $.each(data, function(o, d) {
                            $('.ui_buttons').append('<button name="source" value="' + d.classify_id + '" class="button ">' + d.classify_name + '</button>');
                        });
                        $('.ui_buttons').append('<button name="source" value="-2" class="button ">其他</button>');
                    }
                });
        };

        ns.wrapAnalyseData = function (title, data) {
            var $html = $('<dl></dl');
            $html.append('<dt><b>' + title + '</b></dt>');
            $html.append($('<dd></dd>').addClass('ui_trendgrid_number').append($("<strong>0</strong>").text(data.FansCount)));
            $html.append($('<dd></dd>').text('日').append(ns.convertPercent(data.IncreasePercentByDay)));
            $html.append($('<dd></dd>').text('周').append(ns.convertPercent(data.IncreasePercentByWeek)));
            $html.append($('<dd></dd>').text('月').append(ns.convertPercent(data.IncreasePercentByMonth)));

            return $html.wrap('<div class="ui_trendgrid_item"></div>').parent();
        };

        ns.convertPercent = function (perc) {
            if (perc.match(/--/ig)) {
                return '&nbsp;&nbsp;--';
            }
            if (perc.match(/-/ig)) {
                return ' <i title="下降" class="icon_down"></i>' + perc.replace(/-/ig, '');
            }
            return ' <i title="上升" class="icon_up"></i>' + perc;
        };

        ns.setDate = function (d1, d2) {
            ns.startDate = util.formatDate(d1, 'yyyy/MM/dd');
            ns.endDate = util.formatDate(d2, 'yyyy/MM/dd');
            setDataRange(ns.startDate, ns.endDate);
        };

        ns.setCompareDate = function (d1, d2) {
            ns.startCompareDate = util.formatDate(d1, 'yyyy/MM/dd');
            ns.endCompareDate = util.formatDate(d2, 'yyyy/MM/dd');
            setCompareDataRange(ns.startCompareDate, ns.endCompareDate);
        };

        ns.refresh = function () {

            var analyseType = $('#div_item_tabs a.current').attr('bind-value');

            if (analyseType == '1' && !$('#recongitionPanel .button_primary').is('#btn_trendAnalyse')) {
                ns.refreshRecongition();
                ns.gotoPageRecognition(1);
                return;
            }
            if (typeof ns.recongition == "undefined") {
                ns.recongition = -1;
            }

            if (typeof ns.startDate == "undefined" || typeof ns.endDate == "undefined") {
                var day1 = new Date();
                var day2 = new Date();
                day1.setDate(day1.getDate() - 7);
                day2.setDate(day2.getDate() - 1);
                ns.setDate(day1, day2);
            }
            var needReloadDetailData = false;
            if (ns.oldSdate == ns.startDate && ns.oldEdate == ns.endDate) {

            } else {
                needReloadDetailData = true;
                ns.oldSdate = ns.startDate;
                ns.oldEdate = ns.endDate;
            }

            var filterRecongition = $('#div_item_tabs a.current').is('#tab_1');
            var analyseTypes = ['', '新关注人数', '取消关注人数', '净增关注人数', '累积关注人数', '新增注册数', '累积注册数'];

            var compareDefered = $.Deferred();
            // 是否开启对比模式
            if (ns.compareMode) {
                if (typeof ns.startCompareDate == "undefined" || typeof ns.endCompareDate == "undefined") {
                    var day1 = new Date();
                    var day2 = new Date();
                    day1.setDate(day1.getDate() - 14);
                    day2.setDate(day2.getDate() - 8);
                    ns.setCompareDate(day1, day2);
                }
                if (ns.oldCompareSdate == ns.startCompareDate && ns.oldCompareEdate == ns.endCompareDate) {

                } else {
                    needReloadDetailData = true;
                    ns.oldCompareSdate = ns.startCompareDate;
                    ns.oldCompareEdate = ns.endCompareDate;
                }

                $http.get('/api/index.php?r=qmyx/fans-analysis/search-fans-analysis-data', {
                        sdate: ns.startCompareDate,
                        edate: ns.endCompareDate,
                        filter_recognition: filterRecongition || false,
                        recognition: ns.recongition,
                        analyse_type: analyseType
                    })
                    .then(function(data) {
                        var series = [];
                        var chartData = ns.convertSeriesData(ns.startCompareDate, ns.endCompareDate, data);

                        var seriesPrefix = util.formatDate(new Date(ns.startCompareDate), 'MM.dd') + '至' + util.formatDate(new Date(ns.endCompareDate), 'MM.dd');
                        ns.compareSeriesData = {
                            name: seriesPrefix + analyseTypes[analyseType],
                            data: chartData.series
                        };
                        compareDefered.resolve();
                    })
                    .fail(function() {
                        compareDefered.reject();
                    });
            } else {
                compareDefered.resolve();
            }

            if (ns.startDate > ns.endDate) {
                util.alert('开始日期不能大于结束日期');
                return;
            }
            compareDefered.then(function () {
                $http.get('/api/index.php?r=qmyx/fans-analysis/search-fans-analysis-data', {
                        sdate: ns.startDate,
                        edate: ns.endDate,
                        filter_recognition: filterRecongition || false,
                        recognition: ns.recongition,
                        analyse_type: analyseType
                    })
                    .then(function (data) {
                        var series = [];

                        var chartData = ns.convertSeriesData(ns.startDate, ns.endDate, data);
                        var seriesPrefix = util.formatDate(new Date(ns.startDate), 'MM.dd') + '至' + util.formatDate(new Date(ns.endDate), 'MM.dd');

                        series.push({
                            name: (ns.compareMode ? seriesPrefix : "") + analyseTypes[analyseType],
                            data: chartData.series
                        });
                        if (ns.compareMode) {
                            series.push(ns.compareSeriesData);
                        }

                        drawCharts(chartData.xAxis, series, analyseType == "3" ? null : 0);
                    });
            });

            // 是否需要加载详细数据
            if (needReloadDetailData) {
                $http.get('/api/index.php?r=qmyx/fans-analysis/search-fans-analysis-data', {
                        sdate: ns.startDate,
                        edate: ns.endDate,
                        filter_recognition: false,
                        recognition: '',
                        analyse_type: '-1'
                    })
                    .then(function (data) {
                        var sdate = new Date(ns.startDate);
                        var edate = new Date(ns.endDate);
                        var xAxis = [];
                        var seriesData = [];
                        var tmpCumulateUsers = 0;
                        while (sdate <= edate) {
                            var tmpData = { RefDate: util.formatDate(sdate, 'yyyy/MM/dd'), NewUser: 0, CancelUser: 0, NetUser: 0, CumulateUser: tmpCumulateUsers, NewRegUser: 0, CumulateRegUser: 0 };
                            if (data) {
                                var arr = $.grep(data, function (o, i) {
                                    var d = o.AnalyseDate || o.AttentionDate;
                                    if (util.formatDate(d, 'yyyy/MM/dd') == util.formatDate(sdate, 'yyyy/MM/dd')) return true;
                                    return false;
                                });

                                $.each(arr, function (i, o) {
                                    switch (o.AnalyseType) {
                                        case "1":
                                            tmpData.NewUser = o.FansCount;
                                            break;
                                        case "2":
                                            tmpData.CancelUser = o.FansCount;
                                            break;
                                        case "3":
                                            tmpData.NetUser = o.FansCount;
                                            break;
                                        case "4":
                                            tmpData.CumulateUser = o.FansCount;
                                            tmpCumulateUsers = o.FansCount;
                                            break;
                                        case "5":
                                            tmpData.NewRegUser = o.FansCount;
                                            break;
                                        case "6":
                                            tmpData.CumulateRegUser = o.FansCount;
                                            break;
                                    }
                                });
                            }

                            seriesData.push(tmpData);

                            sdate.setDate(sdate.getDate() + 1);
                        }

                        ns.DetailsData = seriesData;
                        $('.page_num').data('curPage', 1);
                        $('.page_num').data('maxPage', Math.ceil(seriesData.length / 14));
                        ns.gotoPage(1, Math.ceil(seriesData.length / 14));
                    });
            } else {
                ns.gotoPage($('.page_num').data('curPage'));
            }

        };

        ns.refreshRecongition = function () {

            $http.get('/api/index.php?r=qmyx/fans-analysis/search-fans-analysis-data-all-recongition', {
                    sdate: ns.startDate,
                    edate: ns.endDate
                })
                .then(function (data) {

                var series = [];

                var seriesData = [];
                $.each(data.Rows, function (i, o) {
                    seriesData.push([
                        o.Title,
                        o.TotalCount
                    ]);
                });

                series.push({
                    type: 'pie',
                    name: '渠道对比',
                    data: seriesData
                });
                if (ns.compareMode) {
                    series.push(ns.compareSeriesData);
                }

                drawPie(series);
            });

            // 是否需要加载详细数据
            $http.get('/api/index.php?r=qmyx/fans-analysis/search-fans-analysis-data-all-recongition-detail', {
                    sdate: ns.startDate,
                    edate: ns.endDate
                })
                .then(function(data) {

                    var sdate = new Date(ns.startDate);
                    var edate = new Date(ns.endDate);
                    var xAxis = [];
                    var seriesData = [];

                    if (data) {
                        $.each(data.Rows, function(i, o) {
                            var tmpData = { Category: '', Title: '', AttentionDate: '', AttentionCount: 0 };
                            tmpData.Category = o.Category;
                            tmpData.Title = o.Title;
                            tmpData.AttentionDate = util.formatDate(o.AttentionDate, 'yyyy/MM/dd');
                            tmpData.AttentionCount = o.AttentionCount;
                            seriesData.push(tmpData);
                        });

                    }


                    ns.DetailsDataRecognition = seriesData;
                    $('.page_num').data('curPage', 1);
                    $('.page_num').data('maxPage', Math.ceil(seriesData.length / 14));
                    ns.gotoPageRecognition(1, Math.ceil(seriesData.length / 14));
                });
        };

        ns.convertSeriesData = function (d1, d2, data) {
            var sdate = new Date(d1);
            var edate = new Date(d2);
            var xAxis = [];

            var seriesData = [];
            while (sdate <= edate) {
                var sval = { name: util.formatDate(sdate, 'MM-dd') };
                xAxis.push(util.formatDate(sdate, 'yyyy/MM/dd'));
                if (data) {
                    var arr = $.grep(data, function (o, i) {
                        var d = o.AnalyseDate || o.AttentionDate;
                        if (util.formatDate(d, 'yyyy/MM/dd') == util.formatDate(sdate, 'yyyy/MM/dd')) return true;
                        return false;
                    });
                    if (arr.length) {
                        //seriesData.push(arr[0].FansCount || arr[0].AttentionCount || 0);
                        sval.y = parseInt(arr[0].FansCount) || parseInt(arr[0].AttentionCount) || 0;
                    } else {
                        //seriesData.push(0);
                        sval.y = 0;
                    }
                } else {
                    //seriesData.push(0);
                    sval.y = 0;
                }

                seriesData.push(sval);
                sdate.setDate(sdate.getDate() + 1);
            }

            return { xAxis: xAxis, series: seriesData };
        };

        ns.gotoPage = function (page, maxPage) {
            if (typeof maxPage == "undefined") {
                maxPage = Math.ceil(ns.DetailsData.length / 14);
            }
            $('.page_num .curpage').text(page);
            $('.page_num .maxpage').text(maxPage);
            $('.page_num').data('curPage', page);
            if (page <= 1) {
                $('.page_prev').hide();
            } else {
                $('.page_prev').show();
            }

            if (page >= maxPage) {
                $('.page_next').hide();
            } else {
                $('.page_next').show();
            }

            page = page - 1;
            var sdate = new Date(ns.startDate);
            sdate.setDate(sdate.getDate() + page * 14);
            var html = '';
            for (var i = 0; i < 14; i++) {
                if (sdate > new Date(ns.endDate)) {
                    break;
                }
                var arr = $.grep(ns.DetailsData, function (o, i) {
                    var d = o.RefDate;
                    if (util.formatDate(d, 'yyyy/MM/dd') == util.formatDate(sdate, 'yyyy/MM/dd')) return true;
                    return false;
                });
                if (arr.length) {
                    html += '<tr>';
                    html += '<td>' + arr[0].RefDate + '</td>';
                    html += '<td style="text-align:right">' + arr[0].NewUser + '</td>';
                    html += '<td style="text-align:right">' + arr[0].CancelUser + '</td>';
                    html += '<td style="text-align:right">' + arr[0].NetUser + '</td>';
                    html += '<td style="text-align:right">' + arr[0].CumulateUser + '</td>';
                    html += '<td style="text-align:right">' + arr[0].NewRegUser + '</td>';
                    html += '<td style="text-align:right">' + arr[0].CumulateRegUser + '</td>';
                    html += '</tr>';
                }
                sdate.setDate(sdate.getDate() + 1);
            }
            $('#table_list tbody').html(html);
            var thead = '';
            thead += '<tr>';
            thead += '<th>时间</th>';
            thead += '<th>新关注人数</th>';
            thead += '<th>取消关注人数</th>';
            thead += '<th>净增关注人数</th>';
            thead += '<th>累积关注人数</th>';
            thead += '<th>新注册人数</th>';
            thead += '<th>累积注册人数</th>';
            thead += '</tr>';

            $('#table_list thead').html(thead);
        };

        ns.gotoPageRecognition = function (page, maxPage) {
            if (typeof maxPage == "undefined") {
                maxPage = Math.ceil(ns.DetailsDataRecognition.length / 14);
            }
            $('.page_num .curpage').text(page);
            $('.page_num .maxpage').text(maxPage);
            $('.page_num').data('curPage', page);
            if (page <= 1) {
                $('.page_prev').hide();
            } else {
                $('.page_prev').show();
            }

            if (page >= maxPage) {
                $('.page_next').hide();
            } else {
                $('.page_next').show();
            }

            page = page - 1;
            var sdate = new Date(ns.startDate);
            sdate.setDate(sdate.getDate() + page * 14);
            var html = '';
            for (var i = 0; i < 14; i++) {
                var idx = page * 14 + i;
                if (idx >= ns.DetailsDataRecognition.length) {
                    break;
                }
                var item = ns.DetailsDataRecognition[idx];
                if (item) {
                    html += '<tr>';
                    html += '<td>' + item.Category + '</td>';
                    html += '<td>' + item.Title + '</td>';
                    html += '<td style="text-align:center">' + item.AttentionDate + '</td>';
                    html += '<td style="text-align:right">' + item.AttentionCount + '</td>';
                    html += '</tr>';
                }
            }
            $('#table_list tbody').html(html);
            var thead = '';
            thead += '<tr>';
            thead += '<th>渠道分类</th>';
            thead += '<th>渠道名称</th>';
            thead += '<th>关注日期</th>';
            thead += '<th>关注数量</th>';
            thead += '</tr>';

            $('#table_list thead').html(thead);
        };

        $(function () {
            FansAnalyse.InitFansAnalyseData();
            $('#div_item_tabs a:link').on('click', function (e) {

                $('#div_item_tabs a:link.current').removeClass('current');
                $(e.target).addClass('current');
                if ($(e.target).is('#tab_1')) {
                    $('.ui_filter_content').show();
                } else {
                    $('.ui_filter_content').hide();
                }
                ns.refresh();
            });

            $('#toolbar a:link').on('click', function (e) {
                $('#toolbar li.active,#date').removeClass('active');
                $(e.target).closest('li').addClass('active');
                var num = parseInt($(e.target).attr('per-data'));
                var day1 = new Date();
                var day2 = new Date();
                day1.setDate(day1.getDate() - num);
                day2.setDate(day2.getDate() - 1);
                ns.setDate(day1, day2);
                day1.setDate(day1.getDate() - num);
                day2.setDate(day2.getDate() - num);
                ns.setCompareDate(day1, day2);
                ns.refresh();
            });

            $('#div_source').on('click', '.button', function (e) {
                $('#div_source .button').removeClass('current');
                $(e.target).addClass('current');
                ns.recongition = $(e.target).val();
                ns.refresh();
            });

            $('.page_prev').on('click', function (e) {
                var curPage = parseInt($('.page_num').data('curPage'));
                var maxPage = parseInt($('.page_num').data('maxPage'));
                if (curPage <= 1) {
                    return;
                }
                ns.gotoPage(--curPage, maxPage);
            });
            $('.page_next').on('click', function (e) {
                var curPage = parseInt($('.page_num').data('curPage'));
                var maxPage = parseInt($('.page_num').data('maxPage'));
                if (curPage >= maxPage) {
                    return;
                }
                ns.gotoPage(++curPage, maxPage);
            });
            $('.page_go').on('click', function (e) {
                var page = parseInt($(e.target).prev().val());
                var curPage = parseInt($('.page_num').data('curPage'));
                var maxPage = parseInt($('.page_num').data('maxPage'));
                if (page >= 1 && page <= maxPage) {
                    ns.gotoPage(page, maxPage);
                }
            });
            $('#btn_compare').click(function(e) {
                if (ns.compareMode == 1) {
                    ns.compareMode = 0;
                    $(e.target).text('按时间对比');
                    $('.contrast,#div_compare_date').hide();
                    $('#short_opt,#recongitionPanel').show();
                } else {
                    ns.compareMode = 1;
                    $(e.target).text('取消对比');
                    $('.contrast,#div_compare_date').show();
                    $('#short_opt,#recongitionPanel').hide();
                }
                ns.refresh();
            });
            //$('#btn_compare').toggle(function (e) {
            //    ns.compareMode = 1;
            //    $(e.target).text('取消对比');
            //    $('.contrast,#div_compare_date').show();
            //    $('#short_opt,#recongitionPanel').hide();
            //    ns.refresh();
            //}, function (e) {
            //    ns.compareMode = 0;
            //    $(e.target).text('按时间对比');
            //    $('.contrast,#div_compare_date').hide();
            //    $('#short_opt,#recongitionPanel').show();
            //    ns.refresh();
            //});
            $('#recongitionPanel .button').on('click', function(e) {
                $('#recongitionPanel .button').removeClass('button_primary');
                $(e.target).addClass('button_primary');
                if ($(e.target).is('#btn_trendAnalyse')) {
                    $('#div_source,#source_text,#btn_compare').show();
                    ns.refresh();
                    ns.gotoPage(1);
                } else {
                    $('#div_source,#source_text,#btn_compare').hide();
                    ns.refreshRecongition();
                    ns.gotoPageRecognition(1);
                }
            });

            $('#date').dateRangePicker({
                language: "cn", separator: " 至 ",
                setValue: function (s) {
                    this.value = s;
                    $('#date').text(s);
                }
            }).bind('datepicker-apply', function (event, obj) {
                if (!obj.date1.getDay() || !obj.date2.getDay()) {
                    mini.alert('请选择有效的日期区间');
                    return;
                }
                $('#date').text(obj.value);
                $('#toolbar li.active,#date').removeClass('active');
                $('#date').addClass('active');
                ns.setDate(obj.date1, obj.date2);
                ns.refresh();
            });
            var d = new Date();
            d.setDate(d.getDate() - 60);

            $('#date').data('dateRangePicker').setDateRange(d.format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd'));

            $('#dateCompare').dateRangePicker({
                language: "cn", separator: " 至 ",
                setValue: function (s) {
                    this.value = s;
                    $('#dateCompare').text(s);
                }
            }).bind('datepicker-apply', function (event, obj) {
                if (!obj.date1.getDay() || !obj.date2.getDay()) {
                    mini.alert('请选择有效的日期区间');
                    return;
                }
                $('#dateCompare').text(obj.value);
                ns.setDate(obj.date1, obj.date2);
                ns.refresh();
            });
            var d = new Date();
            d.setDate(d.getDate() - 60);

            $('#dateCompare').data('dateRangePicker').setDateRange(d.format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd'));

            ns.refresh();
        });

    })(FansAnalyse);

    function drawCharts(categories, series, minYAxis) {
        var chart = new Highcharts.Chart({                   //图表展示容器，与div的id保持一致
            chart: {
                renderTo: 'charts-container',
                type: 'line'                         //指定图表的类型，默认是折线图（line）
            },
            enableZoom: true,
            autoStep: false,                         //自动计算步长
            showPlotLine: false,                    //是否显示中位线 
            enableLegend: true,                     //是否显示图例
            autoYAxisInterval: false,                //自动计算Y轴间隔
            maxYAxisIntervalCount: 3,               //Y轴最大刻度数 
            floor: 0,
            min: 50,
            tooltip: {
                crosshairs: { dashStyle: "ShortDot", color: "#666666" },
                shared: true,
                formatter: function () {
                    var s = '<b>' + this.x + '</b>';

                    $.each(this.points, function () {
                        s += '<br/>' + this.series.name + '(' + this.key + ')' + ': ' +
                            this.y;
                    });

                    return s;
                }
            },
            tickLength: 20,
            plotOptions: { spline: { marker: { radius: 4, lineColor: '#666666', lineWidth: 1 } } },
            title: {
                text: ''      //指定图表标题
            },
            xAxis: {
                categories: categories,  //指定x轴分组

                tickInterval: Math.floor(categories.length / 6)
            },
            yAxis: {
                title: {
                    text: '人数'                  //指定y轴的标题
                },
                min: minYAxis,
                allowDecimals: false
            },
            series: series
        });
    };

    function drawPie(series) {
        $('#charts-container').highcharts({
            chart: { plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false },
            title: { text: '' },
            tooltip: { pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>' },
            plotOptions: {
                pie: {
                    allowPointSelect: true, cursor: 'pointer',
                    dataLabels: {
                        enabled: true, color: '#000000', connectorColor: '#000000', format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                    }
                }
            }, series: series
        });
    }

    function setDataRange(d1, d2) {
        $('#date').data('dateRangePicker').setDateRange(d1, d2);
    }
    function setCompareDataRange(d1, d2) {
        $('#dateCompare').data('dateRangePicker').setDateRange(d1, d2);
    }



    module.exports = FansAnalyse;
});